% Run Tower of Psych and Snow Dots unit tests, under a few configurations.
function repeatAllDotsTests

% keep track of test outuput in a "diary" file
cd('~')
diaryFile = [mfilename, '.txt'];
if exist(diaryFile)
    delete(diaryFile);
end
diary(diaryFile);
diary('on')

try
    % run the Towet of Psych tests, once
    clear
    clear classes
    clear mex
    passed = runAllTopsTests;
    assert(passed, 'tops tests failed')
    
    % run the Snow Dots tests with no client or server mode
    clear
    clear classes
    clear mex
    passed = runAllDotsTests('setUpFunction', @()resetter(false, false))
    assert(passed, 'dots tests failed')
    
    % run the Snow Dots tests with both client and server mode
    clear
    clear classes
    clear mex
    passed = runAllDotsTests('setUpFunction', @()resetter(true, true))
    assert(passed, 'dots tests failed')
    
    % run the Snow Dots tests with a client on this machine and server in a
    % separate Matlab instance
    clear
    clear classes
    clear mex
    input('Start the server, please.', 's')
    passed = runAllDotsTests('setUpFunction', @()resetter(true, false))
    assert(passed, 'dots tests failed')
    
catch err
    err
end

diary('off')

% called from dotsTestCase for each test to reselect client and server mode
function resetter(client, server)
disp(sprintf('%s: clientMode:%d serverMode:%d', ...
    mfilename, client, server));
dotsTheDrawablesManager.reset('clientMode', client, 'serverMode', server);
dotsThePlayablesManager.reset('clientMode', client, 'serverMode', server);
dotsTheComputablesManager.reset('clientMode', client, 'serverMode', server);